package com.summer.order.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.summer.core.annotations.ScopeType;
import com.summer.core.controller.EntityQuery;
import com.summer.order.model.Cookbook;
import com.summer.order.model.OrderSummary;

@Component
@Scope(ScopeType.VIEW)
public class OrderSummaryList extends EntityQuery<OrderSummary> {

	
	private final String HQL = "select orderSummary from OrderSummary orderSummary";
	private final String COUNT_HQL = "select count(orderSummary) from OrderSummary orderSummary";

	private String cookbook_id;

	private Date startDate;

	private Date endDate;

	public OrderSummaryList() {

		setCountHql(COUNT_HQL);
		setHql(HQL);
		final String[] RESTRICTIONS = {

				"orderSummary.cookbook.id like #{orderSummaryList.cookbook_id}"

		};
		setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
	}

	@Override
	protected void initExample() {
		OrderSummary example = new OrderSummary();
		Cookbook cookbook = new Cookbook();
		example.setCookbook(cookbook);
		setExample(example);
	}


	public String getCookbook_id() {

		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		if (startDate != null && endDate != null) {
			cookbook_id = df.format(startDate) + df.format(endDate);
		}
		System.out.println(cookbook_id);
		return cookbook_id;
	}

	public void setCookbook_id(String cookbook_id) {
		this.cookbook_id = cookbook_id;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	
}
